using System;
using System.Collections;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace iDorm
{
	/// <summary>
	/// Summary description for ModelLoader.
	/// </summary>
	public class ModelLoader
	{
		private Hashtable models;
		private string path;

		// Model constructor
		public ModelLoader()
		{
			path = Environment.CurrentDirectory;
		}
		// Loads the model
		public Model LoadModel(Device dev, string file, string texturefile, int color)
		{
			GraphicsStream adj;
			Mesh mesh;
			Texture texture;
			ExtendedMaterial[] matX = null;

			if (file == "")
			{
				mesh = Mesh.Box(dev,1,1,1, out adj);
			}
			else
			{
				mesh = Mesh.FromFile(path + "\\Resources\\" + file, MeshFlags.Managed, dev, out adj, out matX);
			}

			if (texturefile == "")
			{
				texture = null;
			}
			else
			{
				texture = TextureLoader.FromFile(dev, path + "\\Resources\\" + texturefile);
			}

			
			//mesh.ComputeNormals(adj);

			Material material = new Material();
				material.Ambient = System.Drawing.Color.FromArgb(color);
				material.Diffuse = System.Drawing.Color.Black;
				material.Emissive = System.Drawing.Color.Black;
				material.Specular = System.Drawing.Color.Black;

			return new Model(dev, mesh, material, texture, texturefile);
		}
	}
}
